/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.dusin.teachassist.util;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author dusin
 */
public class TheUtil {

    public static String thisSemester() {

        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int no = 1;    //第几学期
        String tempSemester = null;
        switch (month) {
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
                no = 2;
                tempSemester = "" + (year - 1) + "-" + year + "-" + 2;
                break;
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
                no = 1;
                tempSemester = "" + (year) + "-" + (year + 1) + "-" + 1;
                break;
            case 1:
                no = 1;
                tempSemester = "" + (year-1) + "-" + (year) + "-" + 1;
                break;

        }
        return tempSemester;
    }

    public static List<Map<String, Object>> getLast5Semesters() {
        List<Map<String, Object>> semesters = new ArrayList<Map<String, Object>>();
        Map<String, Object> map = null;

        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int no = 1;    //第几学期
        String tempSemester = null;
        switch (month) {
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
                no = 2;
                tempSemester = "" + (year - 1) + "-" + year + "-" + 2;
                
                break;
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
                no = 1;
                tempSemester = "" + (year) + "-" + (year + 1) + "-" + 1;
                break;
            case 1:
                year = year -1;
                no = 1;
                
                break;

        }
        if (no == 2) {
            map = new HashMap<String, Object>();
            map.put("id", 1);
            map.put("text", "" + (year - 1) + "-" + year + "-" + 2);
            semesters.add(map);

            map = new HashMap<String, Object>();
            map.put("id", 2);
            map.put("text", "" + (year - 1) + "-" + year + "-" + 1);
            semesters.add(map);

            map = new HashMap<String, Object>();
            map.put("id", 3);
            map.put("text", "" + (year - 2) + "-" + (year-1) + "-" + 2);
            semesters.add(map);

            map = new HashMap<String, Object>();
            map.put("id", 4);
            map.put("text", "" + (year - 2) + "-" + (year-1) + "-" + 1);
            semesters.add(map);

            map = new HashMap<String, Object>();
            map.put("id", 5);
            map.put("text", "" + (year - 3) + "-" + (year-2) + "-" + 2);
            semesters.add(map);

        } else {
            map = new HashMap<String, Object>();
            map.put("id", 1);
            map.put("text",  "" + (year) + "-" + (year + 1) + "-" + 1);
            semesters.add(map);

            map = new HashMap<String, Object>();
            map.put("id", 2);
            map.put("text", "" + (year - 1) + "-" + year + "-" + 2);
            semesters.add(map);

            map = new HashMap<String, Object>();
            map.put("id", 3);
            map.put("text", "" + (year - 1) + "-" + year + "-" + 1);
            semesters.add(map);

            map = new HashMap<String, Object>();
            map.put("id", 4);
            map.put("text", "" + (year - 2) + "-" + (year-1) + "-" + 2);
            semesters.add(map);

            map = new HashMap<String, Object>();
            map.put("id", 5);
            map.put("text", "" + (year - 2) + "-" + (year-1) + "-" + 1);
            semesters.add(map);

        }
        return semesters;
    }

    public static String getGrade(int score){
        String result = null;
        if(score<60){
            return "F";
        }else if(score>=60&&score<65){
            return "E";
        }else if(score>=65&&score<70){
            return "D";
        }else if(score>=70&&score<75){
            return "C-";
        }else if(score>=75&&score<80){
            return "C";
        }else if(score>=80&&score<85){
            return "B-";
        }else if(score>=85&&score<90){
            return "B";
        }else if(score>=90&&score<95){
            return "A-";
        }else if(score>=95&&score<100){
            return "A";
        }else if(score==100){
            return "A+";
        }
        return result;
    }
}
